<script setup>
  import { onMounted, ref } from "vue";
  import { useStyleStore } from "@/store/styleStore.js";
  import LocalStoreUtil from "@/utils/LocalStoreUtil.js";

  const styleStore = useStyleStore();

  let hover = ref(false);

  // 初始化时显示 3s
  onMounted(() => {
    // 获取缓存中记录的当前用户提示次数
    let count = LocalStoreUtil.getGuideCount();
    count++;
    // 判断当前次数是否需要提醒
    if (count === 0 || count < 3 || count % 30 === 0) {
      // 进行提醒
      setTimeout(() => {
        hover.value = true;
        setTimeout(() => {
          hover.value = false;
        }, 2600);
      }, 400);
    }

    // 更新记录提醒次数
    LocalStoreUtil.setGuideCount(count);
  })

</script>

<template>
  <div :class="['guide-basic', styleStore.guide.status === 1 ? 'basic-show-animation':'', styleStore.guide.status === 2 ? 'basic-hide-animation':'']">
    <router-link class="text" to="/setting/guide" @mouseenter="hover = true" @mouseleave="hover = false">使用指南</router-link>
    <div :class="['vesicle-basic', hover ? 'hover-true':'hover-false']">
      对标签页的操作不太了解时，您可以在这里查看标签页的使用指南！
      <div class="x"></div>
    </div>
  </div>
</template>

<style scoped>
  .guide-basic {
    width: auto;
    height: 30px;
    position: absolute;
    bottom: 15px;
    left: 25px;
    user-select: none;
  }
  .text {
    color: rgb(238, 238, 238);
    text-decoration: none;
    font-size: 14px;
    transition: color .3s;
  }
  .text:hover {
    color: #76e6ea;
  }

  .vesicle-basic {
    width: 210px;
    background-color: rgb(238, 238, 238);
    position: absolute;
    top: -60px;
    left: 24px;
    font-size: 14px;
    padding: 5px 10px;
    border-radius: 5px;
    color: rgb(58, 58, 58);
  }
  .x {
    position: absolute;
    bottom: -8px;
    left: 10px;
    width: 0;
    height: 0;
    border-left:8px solid transparent; /* 左边透明 */
    border-right: 8px solid transparent; /* 右边透明 */
    border-top: 8px solid rgb(238, 238, 238); /* 上边为实心 */
  }

  .hover-true {
    animation-name: hoverTrueAnimation;
    animation-duration: 0.5s;
    animation-fill-mode: forwards;
  }
  .hover-false {
    display: none;
    animation-name: hoverFalseAnimation;
    animation-duration: 0.4s;
    animation-fill-mode: forwards;
  }

  .basic-show-animation {
    animation-name: showAnimation;
    animation-duration: 0.4s;
    animation-fill-mode: forwards;
  }
  .basic-hide-animation {
    display: none;
    animation-name: hideAnimation;
    animation-duration: 0.4s;
    animation-fill-mode: forwards;
  }

  @keyframes showAnimation {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
  @keyframes hideAnimation {
    from {
      display: block;
      opacity: 1;
    }
    to {
      opacity: 0;
    }
  }

  @keyframes hoverTrueAnimation {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
  @keyframes hoverFalseAnimation {
    from {
      display: block;
      opacity: 1;
    }
    to {
      opacity: 0;
    }
  }
</style>